﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using common;

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //string connectionString = @"server=pekdc1-rdb-37.vancloa.cn;database=SCM_WEB;uid=scmweb05user;pwd=scmweb05user@1234;";
            string connectionString = @"server=pekdc1-rdb-38.vancloa.cn;database=MY_SCM;uid=read05user;pwd=read05user@1234;";
            //string connectionString = @"server=PEK7-DEV-02.vancloa.cn;database=MY_SCM;uid=testdbuser;pwd=devuser221;";

            SqlServerHelper.strConnString = connectionString;
            string sql = "select distinct top 10 * from OrderForm where FormCode='111113006590'";
            //string sql = "select distinct top 10 * from Clothes";

            DataTable dt= SqlServerHelper.GetDataTable(sql);
            this.GridView1.DataSource = dt;
            this.GridView1.DataBind();
        }

        /// <summary>
        /// 由GridView导出Excel
        /// </summary>
        /// <param name="ctl">GridView控件ID</param>
        /// <param name="FileName">导出Excel名称</param>
        private void ToExcel(Control ctl, string FileName)
        {
            HttpContext.Current.Response.Charset = "UTF-8";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
            HttpContext.Current.Response.ContentType = "application/ms-excel";
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName);
            ctl.Page.EnableViewState = false;
            System.IO.StringWriter tw = new System.IO.StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(tw);
            ctl.RenderControl(hw);
            HttpContext.Current.Response.Write(tw.ToString());
            HttpContext.Current.Response.End();
        }

        public override void VerifyRenderingInServerForm(Control control)
        {
            //base.VerifyRenderingInServerForm(control);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //GridView1.AllowPaging = false;
            //GridView1.AllowSorting = false;
            //Display();
            ToExcel(GridView1, "word.xls");
            //GridView1.AllowSorting = true;
            //GridView1.AllowPaging = true;
            ////Display();

        }
    }
}